package com.gustuy.chat;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UdpReceive {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(9999);

        while (true) {
            byte[] container=new byte[1024];
            DatagramPacket packet = new DatagramPacket(container, 0, container.length);
            socket.receive(packet);
            String msg=new String(packet.getData(),0,packet.getLength());
            System.out.println(msg);
            if(msg.equals("bye")){
                socket.close();
                break;
            }
        }
    }
}
